from django.db import models


# Create your models here.

class UserInfo(models.Model):
    """用户表"""
    username = models.CharField(verbose_name='用户名', max_length=32, db_index=True)
    email = models.EmailField(verbose_name='邮箱', max_length=32)
    mobile_phone = models.CharField(verbose_name='手机号', max_length=32)
    password = models.CharField(verbose_name='密码', max_length=32)

    def __str__(self):
        return '用户名是{}'.format(self.username)


class PricePolicy(models.Model):
    """价格策略表"""
    category_choices = (
        (1, '免费版本'),
        (2, '收费版本'),
        (3, '其他版本'),
    )
    category = models.SmallIntegerField(verbose_name='收费类型', default=2, choices=category_choices)
    title = models.CharField(verbose_name='标题', max_length=32)
    price = models.PositiveIntegerField(verbose_name='价格')  # 正整数
    project_num = models.PositiveIntegerField(verbose_name='项目数')
    project_member = models.PositiveIntegerField(verbose_name='项目成员数')
    project_space = models.PositiveIntegerField(verbose_name='但项目空间')
    per_file_size = models.PositiveIntegerField(verbose_name='但文件大小（M）')
    create_datetime = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)


class Transaction(models.Model):
    """交易记录表"""
    status_choice = (
        (1, '未支付'),
        (2, '已支付'),
    )
    status = models.SmallIntegerField(verbose_name='状态', choices=status_choice)
    order = models.CharField(verbose_name='订单号', max_length=64, unique=True)
    count = models.IntegerField(verbose_name='数量（年）', help_text='0表示无期限')
    price = models.IntegerField(verbose_name='实际支付价格')
    start_datetime = models.DateTimeField(verbose_name='开始时间', null=True, blank=True)
    end_datetime = models.DateTimeField(verbose_name='结束时间', null=True, blank=True)
    create_datetime = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)

    user = models.ForeignKey(verbose_name='用户', to=UserInfo, on_delete=models.CASCADE)
    price_policy = models.ForeignKey(verbose_name='价格策略', to=PricePolicy, on_delete=models.CASCADE)


class Project(models.Model):
    """项目表"""
    COLOR_CHOICES = (
        (1, '#00F5FF'),
        (2, '#54FF9F'),
        (3, '#00FFFF'),
        (4, '#FFFF00'),
        (5, '#A020F0'),
        (6, '#E8E8E8'),
    )
    name = models.CharField(verbose_name='项目名', max_length=32)
    color = models.SmallIntegerField(verbose_name='颜色', choices=COLOR_CHOICES, default=1)
    desc = models.CharField(verbose_name='项目描述', max_length=255, null=True, blank=True)
    use_space = models.IntegerField(verbose_name='项目使用空间', default=0)
    star = models.BooleanField(verbose_name='星标', default=False)
    join_count = models.SmallIntegerField(verbose_name='参与人数', default=1)
    create_datetime = models.DateTimeField(verbose_name='创建时间', auto_now_add=True)

    creator = models.ForeignKey(verbose_name='创建者', to=UserInfo, on_delete=models.CASCADE)


class ProjectUser(models.Model):
    """项目参与者"""
    user = models.ForeignKey(verbose_name='参与者', to=UserInfo, on_delete=models.CASCADE)
    project = models.ForeignKey(verbose_name='项目', to=Project, on_delete=models.CASCADE)
    star = models.BooleanField(verbose_name='星标', default=False)

    create_datetime = models.DateTimeField(verbose_name='加入时间', auto_now_add=True)










